package Controller.Singer;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import utility.Paging2;

import Bean.JoinBean;
import Bean.SboardBean;
import Bean.SingerBean;
import Bean.rowBean;
import Dao.SingerDao;

public class singerBoardController implements Controller{
	private SingerDao dao;
	Paging2 pageInfo = null;
	public void setDao(SingerDao dao) {
		this.dao = dao;
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest req,
			HttpServletResponse arg1) throws Exception {
		int sb_s_no = Integer.parseInt(req.getParameter("sb_s_no"));
		System.out.println("가수번호"+sb_s_no);
		
		String pageNumber = req.getParameter("pageNumber");
		String pageSize = req.getParameter("pageSize");
		String page = req.getParameter("page");
		
		String url = "";
		String contextPath = req.getContextPath();
		System.out.println(contextPath);
		url = contextPath + "/singerBoard.singer";
		System.out.println("가수 게시판 다오 실행 성공!!");
		/*for (SboardBean sboard : singerboard) {
			System.out.println(sboard.getSb_s_no());
		}*/
		int totalCount = 0 ;
		totalCount = dao.SboardTotal(sb_s_no);
		String param ="?page="+page;
		Integer test = sb_s_no;
		pageInfo = new Paging2(pageNumber, pageSize, totalCount, url, param,test);
		
		rowBean row = new rowBean();
		row.setSb_s_no(sb_s_no);
		row.setBeginRow(pageInfo.getBeginRow());
		row.setEndRow(pageInfo.getEndRow());
		ModelAndView mav = new ModelAndView();
		List<SboardBean> singerboard = dao.Singerboard(row);
		HttpSession session = req.getSession();
		String m_id = (String)session.getAttribute("member");
		if(m_id == null){
			mav.setViewName("InsertError");
			return mav;
		}else{
			for (SboardBean sboard : singerboard) {
				String id = sboard.getSb_m_id();
				if(m_id.equals(id)){
					sboard.setDisable("null");
				}else{
					sboard.setDisable("disabled");
				}
			}	
		}
		mav.setViewName("SboardList");
		mav.addObject("sboard", singerboard);
		mav.addObject("pageInfo", pageInfo);
		mav.addObject("sb_s_no", sb_s_no);
		return mav;
	}

}
